package convertedio;

import java.io.*;

public class ConvertedDemo4 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 序列化
        // method1();

        // 反序列化
        method2();
    }

    /**
     * 反序列化
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
    private static void method2() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("F:\\11\\c.txt"));
        // User o = (User) ois.readObject();
        System.out.println((User) ois.readObject());
        ois.close();
    }

    /**
     * 序列化
     *
     * @throws IOException
     * @throws ClassNotFoundException
     */
    private static void method1() throws IOException, ClassNotFoundException {
        User user = new User("zhangsan", "qwer");
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("F:\\11\\c.txt"));
        oos.writeObject(user);
        oos.close();
    }
}
